package st.magnuzon.books.client.scaffold.ui;

import java.util.HashSet;
import java.util.Set;

import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.text.client.DateTimeFormatRenderer;
import com.google.gwt.text.shared.AbstractRenderer;
import com.google.gwt.text.shared.Renderer;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.TextColumn;

import st.magnuzon.books.client.managed.request.TitleProxy;
import st.magnuzon.books.client.scaffold.place.AbstractProxyListView;

public abstract class TitleListViewer extends AbstractProxyListView<TitleProxy> {
    @UiField
    CellTable<TitleProxy> table;

    protected Set<String> paths = new HashSet<String>();

    public void init() {
        paths.add("id");
        table.addColumn(new TextColumn<TitleProxy>() {

            Renderer<java.lang.Long> renderer = new AbstractRenderer<java.lang.Long>() {

                public String render(java.lang.Long obj) {
                    return obj == null ? "" : String.valueOf(obj);
                }
            };

            @Override
            public String getValue(TitleProxy object) {
                return renderer.render(object.getId());
            }
        }, "Id");
        paths.add("version");
        table.addColumn(new TextColumn<TitleProxy>() {

            Renderer<java.lang.Integer> renderer = new AbstractRenderer<java.lang.Integer>() {

                public String render(java.lang.Integer obj) {
                    return obj == null ? "" : String.valueOf(obj);
                }
            };

            @Override
            public String getValue(TitleProxy object) {
                return renderer.render(object.getVersion());
            }
        }, "Version");
        paths.add("title");
        table.addColumn(new TextColumn<TitleProxy>() {

            Renderer<java.lang.String> renderer = new AbstractRenderer<java.lang.String>() {

                public String render(java.lang.String obj) {
                    return obj == null ? "" : String.valueOf(obj);
                }
            };

            @Override
            public String getValue(TitleProxy object) {
                return renderer.render(object.getTitle());
            }
        }, "Title");
        paths.add("published");
        table.addColumn(new TextColumn<TitleProxy>() {

            Renderer<java.util.Date> renderer = new DateTimeFormatRenderer(DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_SHORT));

            @Override
            public String getValue(TitleProxy object) {
                return renderer.render(object.getPublished());
            }
        }, "Published");
        paths.add("isbn");
        table.addColumn(new TextColumn<TitleProxy>() {

            Renderer<java.lang.Integer> renderer = new AbstractRenderer<java.lang.Integer>() {

                public String render(java.lang.Integer obj) {
                    return obj == null ? "" : String.valueOf(obj);
                }
            };

            @Override
            public String getValue(TitleProxy object) {
                return renderer.render(object.getIsbn());
            }
        }, "Isbn");
        paths.add("authors");
        table.addColumn(new TextColumn<TitleProxy>() {

            Renderer<java.util.Set> renderer = st.magnuzon.books.client.scaffold.place.CollectionRenderer.of(st.magnuzon.books.client.managed.ui.AuthorProxyRenderer.instance());

            @Override
            public String getValue(TitleProxy object) {
                return renderer.render(object.getAuthors());
            }
        }, "Authors");
    }
}
